﻿using Microsoft.Phone.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Data;

namespace Smile.Xaml
{
    public static class BindingHelper
    {
        public static void UpdateBinding(TextBox textBox)
        {
            BindingExpression bindingExpression =
                    textBox.GetBindingExpression(TextBox.TextProperty);
            if (bindingExpression != null)
            {
                bindingExpression.UpdateSource();
            }
        }

        public static void UpdateBinding(PasswordBox paswordBox)
        {
            BindingExpression bindingExpression =
                    paswordBox.GetBindingExpression(PasswordBox.PasswordProperty);
            if (bindingExpression != null)
            {
                bindingExpression.UpdateSource();
            }
        }

        public static void UpdateBinding(CheckBox checkbox)
        {
            BindingExpression bindingExpression =
                    checkbox.GetBindingExpression(CheckBox.IsCheckedProperty);
            if (bindingExpression != null)
            {
                bindingExpression.UpdateSource();
            }
        }

        public static void UpdateBinding(LongListSelector list)
        {
            BindingExpression bindingExpression = 
                list.GetBindingExpression(LongListSelector.ItemTemplateProperty);
            if (bindingExpression != null)
            {
                bindingExpression.UpdateSource();
            }
            list.ApplyTemplate();
        }
    }
}
